

cc.Class({
    extends: cc.Component,

    properties: {
        scorePrefab: cc.Prefab
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.scorePool = new cc.NodePool();
        this.scorePool.put(cc.instantiate(this.scorePrefab));
    },

    start () {

    },

    // update (dt) {},

    showAddScore(score, pos){
        let clone = null;
        if (this.scorePool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            clone = this.scorePool.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            clone = cc.instantiate(this.scorePrefab);
        }
        clone.parent = this.node; // 将生成的敌人加入节点树
        clone.setPosition(pos);

        clone.getComponent(cc.Label).string = '+' + score;
        clone.opacity = 255;
        //向上淡出的动画.
        var anim = cc.spawn(cc.fadeOut(0.8), cc.moveBy(0.8, cc.p(0, 100)));
        clone.runAction(anim);
        this.scheduleOnce(function() {
            this.scorePool.put(clone);
        }, 0.8);
    },
});
